<?php
//require_once 'db.php';
define("HOST", "localhost");
define("USER", "root");
define("PASS", "gz19991215@");
define("DATABASE", "gao");
//1、建立链接
$link = mysqli_connect(HOST,USER,PASS);
if (!$link){
    exit("数据库链接失败！");
}
//2、选择数据库
mysqli_select_db($link,DATABASE);


//3、执行sql语句
$strsql = "select*from student";
$result =  mysqli_query($link, $strsql);
//4、处理结果集
//$row = mysqli_fetch_array($result);
// $row = mysqli_fetch_assoc($result);
// $row = mysqli_fetch_row($result);
// $row = mysqli_fetch_all($result);
$data = array();
while ($row = mysqli_fetch_array($result)){
    $data[] = $row;
}
// echo "<pre>";
// print_r($row);
// echo "<pre>";
//5、释放资源，关闭链接
mysqli_free_result($result);
mysqli_close($link);



?>
<!DOCTYPE>
<html>
<head>
<title>数据库</title>
</head>
<body>
    <table>
    	<tr>
    		<th>序号</th>
    		<th>姓名</th>
    		<th>性别</th>
    		<th>成绩</th>
    	</tr>
    	<?php 
    	foreach ($data as $key => $value){
    	?>
    	<tr>
    		<th><?= $value[0]?></th>
    		<th><?= $value[1]?></th>
    		<th><?= $value["gender"]?></th>
    		<th><?= $value["grades"]?></th>
    	</tr>
    	<?php 
    	}?>
    </table>
</body>
</html>
